package com.example.diagnodroid.ecran;


import com.example.diagnodroid.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class DrawActivity extends Activity {

	private DrawView drawView;
	private TextView resX;
	private TextView resY;
	private Button btnReset;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.draw_layout);
		
		drawView = (DrawView) findViewById(R.id.drawView);
		resX = (TextView) findViewById(R.id.resX);
		resY = (TextView) findViewById(R.id.resY);
		btnReset = (Button) findViewById(R.id.btnReset);
		
		btnReset.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				drawView.resetDraw();
			}
		});
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		
		float x = event.getX();
		float y = event.getY() - getActionBar().getHeight();

		resX.setText(""+x);
		resY.setText(""+y);
		
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			drawView.touch_start(x, y);
			drawView.invalidate();
			break;
		case MotionEvent.ACTION_MOVE:
			drawView.touch_move(x, y);
			drawView.invalidate();
			break;
		case MotionEvent.ACTION_UP:
			drawView.touch_up();
			drawView.invalidate();
			break;
		}
		
		return true;
	}
}
